package com.aglhz.nature.adapter;

import java.util.List;

import com.aglhz.nature.R;
import com.aglhz.nature.adapter.SearchAdapter.ViewHolder;
import com.aglhz.nature.modle.item.SearchData;
import com.aglhz.nature.modle.item.ShopListData;
import com.aglhz.nature.view.HomeReWebActivity;
import com.aglhz.nature.view.SecondHomeWebActivity;
import com.squareup.picasso.Picasso;

import android.content.Context;
import android.content.Intent;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class SecondHomeREAdapter extends BaseAdapter{

	public List<ShopListData>mData;
    public Context context;
	public SecondHomeREAdapter(List<ShopListData> mData, Context context) {
		super();
		this.mData = mData;
		this.context = context;
	}
    
	@Override
	public int getCount() {
		return mData.size();
	}
	@Override
	public Object getItem(int position) {
		return mData.get(position);
	}
	@Override
	public long getItemId(int position) {
		return position;
	}
	@Override
	public View getView(final int position, View convertView, ViewGroup arg2) {
		
		 ViewHolder viewHolder; 
			if(null==convertView){			
				  convertView = LayoutInflater.from(context).inflate(R.layout.item_secclass_listview, null); 
				  viewHolder = new ViewHolder();
				  viewHolder.relativelayout=(RelativeLayout) convertView.findViewById(R.id.relativelayout);
				   viewHolder.goodsName=(TextView) convertView.findViewById(R.id.goodsName);
				  
				   viewHolder.second_cla_tvMoney=(TextView) convertView.findViewById(R.id.second_cla_tvMoney);				
				   viewHolder.second_cla_iv=(ImageView) convertView.findViewById(R.id.second_cla_iv);
				   viewHolder.relativelayout.setOnClickListener(new OnClickListener() {
					
					@Override
					public void onClick(View v) {
						Intent intent=new Intent(context,SecondHomeWebActivity.class);
						intent.putExtra("HomeSecLIST",mData.get(position).getLink());
						context.startActivity(intent);
						
					}
				});
				  convertView.setTag(viewHolder); 
			}else{
				viewHolder = (ViewHolder) convertView.getTag(); 
			}
//			//设置图片
//			RelativeLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);  
//			lp.setMargins((int)(getScreenWidth()*0.025), (int)(getScreenWidth()*0.025), (int)(getScreenWidth()*0.025), (int)(getScreenWidth()*0.025));		
//			viewHolder.second_cla_iv.setLayoutParams(lp); 
			
				  String imgUrl = mData.get(position).getGoodsImgCover();
				//picasso加载网络图片
				   Picasso.with(context)  
				   .load(imgUrl)  	
				   .resize(getScreenWidth(), getScreenWidth()*2/5)
				    .error(R.drawable.shoplist_bg)
				   .into(viewHolder.second_cla_iv) ;
	   
			//设置文字
				   viewHolder.goodsName.setText(mData.get(position).getName());

					viewHolder.second_cla_tvMoney.setText("￥："+mData.get(position).getPrice());
				
			
	

			return convertView;
		}
		class ViewHolder 
		{  
			public RelativeLayout relativelayout;
			public TextView goodsName;
			
			public TextView second_cla_tvMoney;
			public ImageView second_cla_iv;
	
		} 
		/**
		 * 获取屏幕宽度
		 * 
		 * @return
		 */
		protected int getScreenWidth() {
			WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
			Display display = wm.getDefaultDisplay();
			return display.getWidth();
		}
}
